<template>
  <div class="wrap">
    <m-header></m-header>
    <ul v-for="item in allUserList">
      <li style="display: flex">
        <p>{{ item.socketID }}</p>
        <router-link :to="`/message?id=` + item.id">
          <Button @click="addConver(item.id)">聊天</Button>
        </router-link>
      </li>
    </ul>
  </div>
</template>

<script>
import mHeader from "@/components/header.vue";
import { getSession,setSession } from "@/utils/index.js";

export default {
  components: {
    mHeader,
  },
  data() {
    return {
      allUserList:[]
    };
  },
  created() {
    // this.getUserInfo();
    this.getAllUser();
  },
  methods: {
    // 获取个人信息
    getUserInfo() {
      this.HttpService.getUserInfo().then((res) => {
        console.log(res);
        setSession("userInfo", res.data);
      });
    },
    // 获取聊天列表
    getAllUser() {
      this.HttpService.getAllUser().then((res) => {
        this.allUserList = res.data.data;
      });
    },
    addConver(receiverId) {
      let { id } = getSession('userInfo')
      this.HttpService.addConversation({ sender: id, receiverId: receiverId }).then(
        (res) => {
          console.log(res);
        }
      );
    },
  },
};
</script>

<style lang='less' scoped>
</style>
